package org.joy;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.http.apache.client.impl.SdkHttpClient;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ListObjectsV2Result;
import com.amazonaws.services.s3.model.S3ObjectSummary;

import java.util.List;

public class S3v1function {
    private static  String accessKeyId = "79cb604a0935c1a96fec9fbb8029e1bd309275a7";
    private static  String accessKeySecret = "1Ac0FttRtC8uIWk+odX/05t9oC8CYnHdqEVUU1X8ZSU=";

    public static void main(String[] args) {
        String bucket_name = "buckettest";

        AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, accessKeySecret)))
//                .withCredentials(InstanceProfileCredentialsProvider.getInstance())
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
                        "https://cnjxmruwj0jf.compat.objectstorage.ap-singapore-1.oraclecloud.com",
                        ""))
                .withPathStyleAccessEnabled(true)
                .withChunkedEncodingDisabled(true)
                .build();
        ListObjectsV2Result result = s3Client.listObjectsV2(bucket_name);
        List<S3ObjectSummary> objects = result.getObjectSummaries();
        for (S3ObjectSummary os : objects) {
            System.out.println("* " + os.getKey());
        }
    }
}
